import Identicon from '@polkadot/react-identicon';
import usePolkadot from '../../hooks/usePolkadot';
import useTransaction from '../../hooks/useContractFun';

// import abi from '../../abi/Mining.json';

const Home: React.FC = () => {

  const { address, polkadotApi, apiState, transfer } = usePolkadot();
  const { executeTx } = useTransaction();

  const size = 32;
  const theme = 'polkadot';

  // const contractAddress = '0x5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFabHE';

  const usage = async () => {
    if (polkadotApi) {
      // The length of an epoch (session) in Babe
      // console.log(polkadotApi.consts.babe.epochDuration.toNumber());

      // Retrieve the last timestamp
      // const now = await polkadotApi.query.timestamp.now();

      // Retrieve the account balance & nonce via the system module
      // const { nonce, data: balance } = await polkadotApi.query.system.account(address);

      // console.log(`${now}: balance of ${balance.free} and a nonce of ${nonce}`);

      await transfer('5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFabHE', 100n);
    }
  }

  const send = async () => {
    if (polkadotApi) {
      // await executeTx('new', ['5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFabHE', 100n], contractAddress, abi as any);
    }
  }

  return (
    <div>TEST

      <Identicon
        value={address}
        size={size}
        theme={theme}
      />
      {apiState &&
        <>
          <button onClick={() => usage()}>transfer</button>
          <button onClick={() => send()}>send</button>
        </>
      }
    </div>
  )
}

export default Home